package com.hq.ims.platform.controller;

import com.hq.ims.data.entity.SmsTemplate;
import com.hq.ims.data.service.BaseSmsTemplateService;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.ims.data.vo.SmsTemplateMapstruct;
import com.hq.mybatis.base.page.RequestPage;
import com.hq.mybatis.base.page.ReturnPage;
import com.hq.utils.vo.ReturnVo;
import com.hq.web.annotations.GetJsonValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "短信模板")
@RestController
@RequestMapping(LocalConstant.SYS_TYPE_PLATFORM_URL_PREFIX + "/smsTemplate")

public class PlatformSmsTemplateController {

    @Resource
    private BaseSmsTemplateService baseSmsTemplateService;


    @ApiOperation(value = "获取分页", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getPage", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<ReturnPage<SmsTemplateMapstruct.SmsTemplateVo>> getByAppPage(
            @RequestBody RequestPage page,
            @RequestBody SmsTemplateMapstruct.PageSearchVo searchVo
    ) {
        List<SmsTemplateMapstruct.SmsTemplateVo> voList = baseSmsTemplateService.getByPage(page, searchVo);
        return ReturnVo.buildSuccess(page.getReturnPage());
    }

    @ApiOperation(value = "添加数据", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/addData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> addData(
            @RequestBody SmsTemplateMapstruct.SaveVo saveVo
    ) {
        SmsTemplate data = baseSmsTemplateService.addData(saveVo);
        return ReturnVo.buildSuccess(true);
    }

    @ApiOperation(value = "编辑数据", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/editData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> editData(
            @RequestBody SmsTemplateMapstruct.SaveVo saveVo
    ) {
        SmsTemplate data = baseSmsTemplateService.editData(saveVo);
        return ReturnVo.buildSuccess(true);
    }

    @ApiOperation(value = "获取详情", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getDetail", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<SmsTemplateMapstruct.SmsTemplateVo> getDetail(
            @GetJsonValue(zh = "数据ID") String smsCode
    ) {
        SmsTemplateMapstruct.SmsTemplateVo vo = baseSmsTemplateService.getDetailVo(smsCode);
        return ReturnVo.buildSuccess(vo);
    }

    @ApiOperation(value = "删除数据", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/delData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> delData(
            @GetJsonValue(zh = "数据ID") String smsCode
    ) {
        baseSmsTemplateService.delData(smsCode);
        return ReturnVo.buildSuccess(true);
    }

}